package crl.help
{
	import flash.desktop.ClipboardFormats;
	import flash.desktop.NativeDragActions;
	import flash.desktop.NativeDragManager;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.NativeDragEvent;
	
	/**
	 * 
	 * @author crl
	 * 
	 */	
	public class AirFileDropApp extends Sprite
	{
		private var _hitArea:Sprite;
		public function AirFileDropApp()
		{
			stage.align=StageAlign.TOP_LEFT;
			stage.scaleMode=StageScaleMode.NO_SCALE;
			this.stage.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER,dragEnterHandler);
			this.stage.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP,dragDropHandler);	
			
			_hitArea=new Sprite();
			var g:Graphics=_hitArea.graphics;
			g.beginFill(0x990000,.5);
			g.drawRect(0,0,100,100);
			g.endFill();
			this.addChild(_hitArea);
			
			this.addEventListener(Event.ADDED_TO_STAGE,_stageHandler);
			this.addEventListener(Event.REMOVED_FROM_STAGE,_stageHandler);
		}
		
		private function _stageHandler(event:Event):void{
			if(event.type==Event.ADDED_TO_STAGE){
				stage.addEventListener(Event.RESIZE,resizeHandle);
				resizeHandle(event);
			}else{
				stage.removeEventListener(Event.RESIZE,resizeHandle);
			}
		}
		
		private function resizeHandle(event:Event):void{
			_hitArea.width=stage.stageWidth;
			_hitArea.height=stage.stageHeight;
		}
		
		private function dragEnterHandler(event:NativeDragEvent):void{
			NativeDragManager.acceptDragDrop(this);
			NativeDragManager.dropAction=NativeDragActions.MOVE;
		}
		
		private function dragDropHandler(event:NativeDragEvent):void{
			dragDropFiles(event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array);
		}
		protected function dragDropFiles(list:Array):void{
			
		}
	}
}